package com.yinhechuangji.application.entity;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: yaodx
 * @Date: 2018/9/6 15:10
 * @Description:为Datasource刷新数据用
 */
@RefreshScope
@Component
public class Test {

    @Value("${spring.datasource.url}")
    private  String dbUrl;
    @Value("${spring.datasource.username}")
    private  String username;
    @Value("${spring.datasource.password}")
    private  String password;
    @Value("${spring.datasource.driverClassName}")
    private  String driverClassName;
    @Value("${spring.datasource.initialSize}")
    private  int initialSize;
    @Value("${spring.datasource.minIdle}")
    private  int minIdle;
    @Value("${spring.datasource.maxActive}")
    private  int maxActive;
    //    @Value("${spring.datasource.maxWait}")
//    private int maxWait;
    @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
    private  int timeBetweenEvictionRunsMillis;
    @Value("${spring.datasource.minEvictableIdleTimeMillis}")
    private  int minEvictableIdleTimeMillis;
    @Value("${spring.datasource.validationQuery}")
    private  String validationQuery;
    @Value("${spring.datasource.testWhileIdle}")
    private  boolean testWhileIdle;
    @Value("${spring.datasource.testOnBorrow}")
    private  boolean testOnBorrow;
    @Value("${spring.datasource.testOnReturn}")
    private  boolean testOnReturn;

    public Map<String,Object> getInstance(){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("dbUrl",dbUrl);
        map.put("username",username);
        map.put("password",password);
        map.put("driverClassName",driverClassName);
        map.put("initialSize",initialSize);
        map.put("minIdle",minIdle);
        map.put("maxActive",maxActive);
        map.put("timeBetweenEvictionRunsMillis",timeBetweenEvictionRunsMillis);
        map.put("minEvictableIdleTimeMillis",minEvictableIdleTimeMillis);
        map.put("validationQuery",validationQuery);
        map.put("testWhileIdle",testWhileIdle);
        map.put("testOnBorrow",testOnBorrow);
        map.put("testOnReturn",testOnReturn);
        return map;
    }

    public void setDbUrl(String dbUrl) {
        this.dbUrl = dbUrl;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public void setInitialSize(int initialSize) {
        this.initialSize = initialSize;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }

    public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }

    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    }

    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }

    public void setTestWhileIdle(boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }

    public void setTestOnBorrow(boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public void setTestOnReturn(boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }

    public String getDbUrl() {
        return dbUrl;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public int getInitialSize() {
        return initialSize;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public int getMaxActive() {
        return maxActive;
    }

    public int getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }

    public int getMinEvictableIdleTimeMillis() {
        return minEvictableIdleTimeMillis;
    }

    public String getValidationQuery() {
        return validationQuery;
    }

    public boolean isTestWhileIdle() {
        return testWhileIdle;
    }

    public boolean isTestOnBorrow() {
        return testOnBorrow;
    }

    public boolean isTestOnReturn() {
        return testOnReturn;
    }
}
